<template>
  <el-dialog :visible.sync="dialog" append-to-body title="执行日志" width="88%">
    <!-- 搜索 -->
    <div class="head-container">
      <el-input v-model="params.className" clearable placeholder="输入任务名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toPageQuery"/>
      <el-date-picker
        v-model="params.date"
        type="daterange"
        range-separator=":"
        class="el-range-editor--small filter-item"
        style="height: 30.5px;width: 220px"
        value-format="yyyy-MM-dd HH:mm:ss"
        start-placeholder="开始日期"
        end-placeholder="结束日期"/>
      <el-select v-model="params.state" placeholder="日志状态" clearable class="filter-item" style="width: 110px" @change="toPageQuery">
        <el-option v-for="item in enabledTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toPageQuery">搜索</el-button>
    </div>
    <!--表格渲染-->
    <el-table
      v-loading="loading"
      :data="data"
      border
      stripe
      size="small"
      style="width: 100%;margin-top: -10px;">
      <el-table-column align="center" prop="className" label="任务类路径"/>
      <el-table-column align="center" prop="cronExpression" label="cron表达式"/>
      <el-table-column align="center" prop="times" width="100px" label="耗时(毫秒)"/>
      <el-table-column align="center" prop="state" width="80px" label="状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.state==0 ? 'success' : 'danger'">{{ scope.row.state==0 ? '成功' : '失败' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="params" label="描述"/>
      <el-table-column align="center" prop="createTime" label="创建日期"/>
      <el-table-column align="center" prop="createTime" label="异常详情" width="110px">
        <template slot-scope="scope">
          <el-button v-show="scope.row.errors" size="mini" type="text" @click="info(scope.row.errors)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :visible.sync="errorDialog" append-to-body title="异常详情" width="85%">
      <span>
        {{ errorInfo }}
      </span>
    </el-dialog>
    <!--分页组件-->
    <el-pagination
      :total="totalCount"
      :current-page="currentPage + 1"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
  </el-dialog>
</template>

<script>
import initData from '@/mixins/initData'
import { listPage } from '@/api/timingLog'
export default {
  mixins: [initData],
  data() {
    return {
      errorInfo: '',
      errorDialog: false,
      dialog: false,
      enabledTypeOptions: [
        { key: '0', display_name: '成功' },
        { key: '1', display_name: '失败' }
      ]
    }
  },
  created() {
    this.$nextTick(() => {
      this.initPageData()
    })
  },
  methods: {
    beforeInit() {
      this.url = listPage
      if (this.params.date) {
        this.params['createTimeStart'] = this.params.date[0]
        this.params['createTimeEnd'] = this.params.date[1]
      }
      return true
    },
    info(errorInfo) {
      this.errorInfo = errorInfo
      this.errorDialog = true
    }
  }
}
</script>
